//测试-循环链表
//编译：g++ TestCircularLinkedList.cpp ../../*/*/CircularLinkedList.hpp ../../*/ExceptionDefinition.hpp -o test
#ifndef __TESTCIRCULARLINKEDLIST__CPP
#define __TESTCIRCULARLINKEDLIST__CPP

#include<iostream>
#include"../../DataStructure/LinkedList/CircularLinkedList.hpp"
#include"../../DataStructure/ExceptionDefinition.hpp"

using namespace std;
using namespace NgSiuKei;

int main(void) {
    //初始化
    cout << "初始化" << endl;
    CircularLinkedList<int> list;
    //验证表是不是大小为0
    if(list.isEmpty()) {
        cout << "size = " << list.getSize() << endl;
    }
    //取第一个元素
    cout << "取第一个元素，应该会显示抛出异常：越界" << endl;
    try {
        list.getVal(0);
    }
    catch(Exception & exception) {
        printException(exception);
    }
    try {
        //批量插入数据[ 0 , 1 , 2 , 3 , 4 ]
        cout << "批量插入数据[ 0 , 1 , 2 , 3 , 4 ]" << endl;
        for(int i=0; i<5; ++i) {
            list.insertVal(i, i);
        }
        list.print();
        cout << "此时表大小为：" << list.getSize() << endl;
        //获取下标为2的值
        cout << "下标为2的值：" << list.getVal(2) << endl;
        //查找值3
        cout << "数值3的下标为：" << list.findVal(3) << endl;
        //查找值100，此时应该捕捉到异常
        cout << "数值100的下标为：";
        try {
            cout << list.findVal(100) << endl;
        }
        catch(Exception & exception) {
            printException(exception);
        }
        //在下标1的位置插入值100
        cout << "在下标1的位置插入值100" << endl;
        list.insertVal(100, 1);
        cout << "此时表大小为：" << list.getSize() << endl;
        list.print();
        //查找值100，此时应该获得1
        cout << "数值100的下标为：" << list.findVal(100) << endl;
        //删除下标为2的值
        cout << "删除下标为2的值：" << list.deleteWithIndex(2) << endl;
        cout << "此时表大小为：" << list.getSize() << endl;
        list.print();
    }
    catch(Exception & exception) {
        printException(exception);
    }

    return 0;
};

#endif